package com.portal.controller;

import com.portal.model.entity.BookType;
import com.portal.service.BookTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 书籍分类
 */
@RestController
@RequestMapping("/bookType")
@Tag(name = "书籍分类")
//@CrossOrigin(origins = "http://localhost:9000") // origins = "*" 允许所有的访问来源
public class BookTypeController {

    @Autowired
    private BookTypeService bookTypeService;

    /**
     * 查询所有的书籍分类 http://localhost:8080/bookType/findAll
     */
    @GetMapping("/findAll")
    @Operation(summary = "查询所有的书籍分类")
    public ResponseEntity<List<BookType>> findAll() {
        // 如果直接在这里使用缓存：1、先从redis中查询； 2、如果没有查到，查询数据库，结果放入返回； 3、如果查到了直接返回
        List<BookType> types = bookTypeService.findAll();
        return ResponseEntity.ok(types);
    }
}